<template>
  <div class="login">
    <div class="box">
      <div class="imgBox">
        <img src="@/assets/logo.png" alt="" />
      </div>
      <!-- // 表单 -->
      <el-form :model="Form" :rules="rulesLogin" ref="ruleForm">
        <el-form-item prop="username">
          <el-input
            prefix-icon="iconfont icon-username"
            v-model="Form.username"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            prefix-icon="iconfont icon-password"
            v-model="Form.password"
            placeholder="请输入密码"
            show-password
            type="password"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="btn">
        <el-button type="primary" @click="goLogin">登录</el-button>
        <el-button type="info" @click="cz">重置</el-button>
      </div>
    </div>
  </div>
</template>

<script>
// import { Loginapi } from '@/http/api'
export default {
  name: '',
  components: {},
  data() {
    return {
      // 表单
      Form: {
        username: 'admin',
        password: '123456'
      },
      rulesLogin: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    goLogin() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (!valid) {
          return false
        } else {
          const res = await this.$QHL.Loginapi(this.Form)
          console.log(res)
          sessionStorage.setItem('token', res.token)
          this.$router.push('/home')
        }
      })
    },
    cz() {
      this.$refs.ruleForm.resetFields()
    }
  }
}
</script>
<style scoped lang="scss">
.login {
  height: 100%;
  background: #2b4b6b;
  .box {
    width: 20%;
    height: 300px;
    background: #fff;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    min-width: 500px;
    padding: 0 40px;
    box-sizing: border-box;
    border-radius: 10px;
    box-shadow: 0 0 40px #ccc;
    .imgBox {
      width: 130px;
      height: 130px;
      border-radius: 50%;
      border: 1px solid #fff;
      // padding: 5px;
      margin-left: 150px;
      margin-top: -70px;
      box-shadow: 0 0 10px 10px #ccc;
      background: #fff;
      img {
        width: 110px;
        height: 110px;
        margin-top: 10px;
        border-radius: 50%;
        background: #efefef;
        margin-left: 10px;
        // box-shadow: 0 0 10px 10px #ccc;
      }
    }

    .el-form {
      margin-top: 20px;
    }
  }
  .btn {
    float: right;
  }
}
</style>
